<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>第二周/01/6数据类型转换.html</title>
</head>

<body>
  输入三位数:<input type="text" id="input" />
  <button onclick="function1()">计算</button>
</body>
<script>
  /*
   * 强转
   * 隐式转换
   *
   * */
  //转Boolean
  console.log(Boolean(undefined));
  console.log(Boolean(null));
  console.log(Boolean(NaN));
  console.log(Boolean(""));
  console.log(Boolean(0));
  console.log(Boolean(1));
  console.log(Boolean(" "));
  console.log(Boolean("aa"));
  console.log(Boolean([]));
  console.log(Boolean({}));
  //转number
  console.log(Number("-100"));

  console.log(Number("123"));
  console.log(Number("张三"));
  console.log(Number("123张三")); //NaN
  console.log(Number("")); //0
  console.log(Number(null)); //0
  console.log(Number(undefined));
  console.log(Number(false));
  console.log(Number(true));
  //转int 只会舍去后面部分开头不是数字全变NaN
  console.log(parseInt("123.12"));
  console.log(parseInt("123.abd"));
  //转浮点数
  console.log(parseFloat("123.1231111111111ab"));
  //转String 字面意思
  console.log(String(123));
  console.log(String(false));
  console.log(String(NaN));
  console.log(String(undefined));
  console.log(String(null));
  console.log(String(["aa", "bb"])); //aa,bb
  console.log(String({})); //[object Object]
  console.log(String([])); //
  //隐式转换
  console.log("abc" - "123"); //NaN
  console.log("123" - "123"); //0
  console.log("123" + "123"); //123123
  console.log(123 + 123); //246
  //isNaN
  console.log(isNaN("23")); //false
  console.log(isNaN("张三")); //ture
  console.log(10 + "undefined");

  //parseInt((a - 100 * parseInt(a / 100)) / 10)
  function function1() {
    var b = document.getElementById("input").value;
    var a = parseInt(b);
    alert(
      parseInt(a / 100) +
      parseInt((a - 100 * parseInt(a / 100)) / 10) +
      a -
      10 * parseInt((a - 100 * parseInt(a / 100)) / 10) -
      100 * parseInt(a / 100)
    );
  }
</script>

</html>